<script setup lang="ts">
import { reactive } from 'vue';
import { toSendMessage ,toCheckLogin} from './request/api';

//数据定义
const data=reactive({
  //提示框信息
  content:"发送验证码",
  //倒计时秒数
  totalTime:60,
  //输入电话号码
  phoneNumber:"",
  //输入验证码
  code:"",
})
//请求发送验证码
const toCountdown=()=>{
  //发送验证码接口
  toSendMessage(data.phoneNumber).then((res)=>{
    console.log(res.data);
  })
  //点击倒计时
  let clock =  window.setInterval(() => {
                data.content = data.totalTime + 's';
                data.totalTime --;
                if( data.totalTime < 0){
                    data.totalTime = 60;
                    data.content = "发送验证码";
                    window.clearInterval(clock);
                }
            }, 1000);
}
//用户登入
const toLogin=()=>{
  toCheckLogin(data.phoneNumber,data.code).then(res=>{
    console.log(res.data);  
  })
}
</script>

<template>
  <div class="login-bg">
    <div class="content">
      <div class="title">
        <h2>LOGIN</h2>
      </div>
      <div class="form-box">
        <div class="login-center">
          <span class="t-name">手机号：</span
          ><input
            type="text"
            name=""
            id="tel_num"
            class="inp phone-inp"
            placeholder="请输入您的手机号"
            v-model="data.phoneNumber"
          />
        </div>
        <div class="login-center">
          <span class="t-name">验证码：</span
          ><input
            type="text"
            name=""
            id="code_num"
            class="inp code-inp"
            v-model="data.code"
            placeholder="请输入您的验证码"
          />
          <div class="get-code ">
            <!-- code-stop 点击事件的禁止 只有totalTime等于60才可点击 -->
            <span class="code-btn" :class="{ 'code-stop' : data.totalTime!=60}" @click="toCountdown">{{data.content}}</span>
          </div>
        </div>
        <div class="login-button" @click="toLogin">登陆</div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.content {
  position: absolute;
  width: 500px;
  height: 450px;
  background-color: #00000060;
  border-radius: 10px;
  top: 50%;
  left: 50%;
  margin-left: -240px;
  margin-top: -240px;
  padding: 10px 20px;
  box-sizing: border-box;
  text-align: center;
}
.title h2 {
  font-size: 45px;
  line-height: 60px;
  color: #ffffff90;
  font-weight: bold;
  text-align: center;
}
.login-center {
  height: 50px;
  border-radius: 5px;
  border: 1px solid #00aced;
  margin-bottom: 30px;
  line-height: 50px;
  padding: 0 10px;
  box-sizing: border-box;
  color: #fff;
  input {
    color: #fff;
  }
}
.login-center .t-name {
  font-size: 20px;
  float: left;
  height: 100%;
  width: 85px;
}
.login-center .inp {
  font-size: 24px;
  float: left;
  border: none;
  background: transparent;
  height: 100%;
  outline: none;
}
.login-center .inp.code-inp {
  width: 220px;
}
.login-center .get-code {
  float: right;
  width: 100px;
  height: 100%;
}
.login-center .get-code .code-btn {
  color: gold;
  font-size: 16px;
  width: 100%;
  border: 1px solid gold;
  border-radius: 5px;
  padding: 5px;
  box-sizing: border-box;
  cursor: pointer;
}
.code-stop{
  //禁止点击
   pointer-events: none; 
}
.login-button {
  background-image: linear-gradient(to right, #30cfd0, #330867);
  height: 50px;
  border-radius: 5px;
  font-size: 18px;
  color: #fff;
  text-align: center;
  line-height: 50px;
  cursor: pointer;
}
</style>
